package _1_初级._2_字符串.回文数;

public class _9_回文数 {

    public static boolean isPalindrome(String x) {

        boolean isTrue = true;

        char[] y = x.toCharArray();

        int j = y.length - 1;
        for(int i = 0; i < y.length; i++){
                if(y[i] != y[j]){
                    isTrue = false;
                    break;
                }
             j--;
        }

        return isTrue;
    }

    public static boolean isPalindrome2(int x) {

        boolean isTrue = false;

        int sum = 0;
        int temp;
        int result = x;

        if(x < 0){
            return false;
        }
        while(x != 0){
            temp = x % 10;
            x = x /10;
            sum = sum * 10 + temp;
        }

        System.out.println("x = " + result);
        System.out.println("sum = " + sum);

        if(sum == result){
            isTrue = true;
        }

        return isTrue;
    }

    public static void main(String[] args) {
//        System.out.println(isPalindrome("10"));
        System.out.println(isPalindrome2(1321));
    }
}
